import Vue from 'vue';
import VueRouter from 'vue-router';

const VueRouterPush = VueRouter.prototype.push;
const VueRouterReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err);
};

VueRouter.prototype.replace = function replace(to) {
  return VueRouterReplace.call(this, to).catch((err) => err);
};
Vue.use(VueRouter);

export const routes = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/index/index.vue'),
    meta: {
      title: '松鼠互娱',
      keepAlive: false,
    },
  },
  {
    path: '/hby',
    name: 'hby',
    component: () => import('@/views/hby/index.vue'),
    meta: {
      title: '红包雨',
      keepAlive: false,
    },
  },
  {
    path: '/shake',
    name: 'shake',
    component: () => import('@/views/shake/index.vue'),
    meta: {
      title: '摇一摇',
      keepAlive: false,
    },
  },
  {
    path: '/cattleShake',
    name: 'cattleShake',
    component: () => import('@/views/cattleShake/index.vue'),
    meta: {
      title: '摇一摇',
      keepAlive: false,
    },
  },

  {
    path: '/countMoney',
    name: 'countMoney',
    component: () => import('@/views/countMoney/index.vue'),
    meta: {
      title: '数钞票',
      keepAlive: false,
    },
  },
  {
    path: '/vote',
    name: 'vote',
    component: () => import('@/views/vote/vote.vue'),
    meta: {
      title: '投票',
      keepAlive: false,
    },
  },
  {
    path: '/cutfruit',
    name: 'cutfruit',
    component: () => import('@/views/cutfruit/index.vue'),
    meta: {
      title: '切水果',
      keepAlive: false,
    },
  },
  {
    path: '/photoWall',
    name: 'photoWall',
    component: () => import('@/views/photoWall/index.vue'),
    meta: {
      title: '照片墙',
      keepAlive: false,
    },
  },
  {
    path: '/photographerWall',
    name: 'photographerWall',
    component: () => import('@/views/photographerWall/index.vue'),
    meta: {
      title: '现场照片',
      keepAlive: false,
    },
  },
  {
    path: '/bubbleSign',
    name: 'bubbleSign',
    component: () => import('@/views/bubbleSign/index.vue'),
    meta: {
      title: '手写签到',
      keepAlive: false,
    },
  },
  {
    path: '/clickHb',
    name: 'clickHb',
    component: () => import('@/views/clickHb/index.vue'),
    meta: {
      title: '点红包',
      keepAlive: false,
    },
  },
  {
    path: '/moat',
    name: 'moat',
    component: () => import('@/views/moat/moat.vue'),
    meta: {
      title: '壕榜',
      keepAlive: false,
    },
  },
  {
    path: '/playFootball',
    name: 'playFootball',
    component: () => import('@/views/playFootball/index.vue'),
    meta: {
      title: '谁是射手王',
      keepAlive: false,
    },
  },
  {
    path: '/wishTreeLottery',
    name: 'wishTreeLottery',
    component: () => import('@/views/wishTreeLottery/index.vue'),
    meta: {
      title: '许愿树抽奖',
      keepAlive: false,
    },
  },
  {
    path: '/duiduipeng',
    name: 'duiduipeng',
    component: () => import('@/views/duiduipeng/index.vue'),
    meta: {
      title: '对对碰',
      keepAlive: false,
    },
  },
];

const router = new VueRouter({
  mode: 'hash',
  routes,
});

router.beforeEach((to, from, next) => {
  console.log(from);
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});
export default router;
